/**
 * 业务字典类型管理初始化
 */
var CdcDictype = {
    id: "CdcDictypeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    dataId:"",          //业务数据类型ID
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdcDictype.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '代码', field: 'code', align: 'center', valign: 'middle', sortable: true,width:150},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true,width:200},
        // {title: '业务数据类型', field: 'data.description', align: 'center', valign: 'middle', sortable: true,width:200},
        {title: '是否有效', field: 'isActive', align: 'center', valign: 'middle', sortable: true,width:80,formatter:function(value,row,index) {
            return value?"是":"否";
        }}
    ];
};

/**
 * 检查是否选中
 */
CdcDictype.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcDictype.seItem = selected[0];
        return true;
    }
};

/**
 * 点击新增业务字典类型
 */
CdcDictype.add = function () {
    if (!CdcDictype.dataId) {
        Sys.error("新增失败!请先选择业务数据类型！");
    }else{
        var index = Sys.open('新增业务字典类型',Sys.backendPath + '/cdc/cdcdictype/to_add',['800px', '280px']);
        this.layerIndex = index;
    }
};

/**
 * 打开查看业务字典类型详情
 */
CdcDictype.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('业务字典类型详情',Sys.backendPath + '/cdc/cdcdictype/to_update/' + id,['800px', '280px']);
        this.layerIndex = index;
    }
};

/**
 * 删除业务字典类型
 */
CdcDictype.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/cdc/cdcdictype/delete", function (data) {
	            Sys.success("删除成功!");
	            CdcDictype.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("cdcDictypeId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除业务字典类型?",operation);
    }
};

/**
 * 查询业务字典类型列表
 */
CdcDictype.search = function () {
    var queryData = {};
    queryData['description'] = $("#descriptionType").val();
    queryData['dataId'] = $("#dataId").val();
    queryData['isActive'] = $("#isActive").val();
    CdcDictype.table.refresh({query: queryData});
};
CdcDictype.ClickRow = function(r,e,f){
    CdcDictionary.dictypeId=r.id;
    CdcDictionary.table.clear();
    CdcDictionary.table.refresh({query: {dictypeId:r.id}});
}
$(function () {
    var defaultColunms = CdcDictype.initColumn();
    var table = new BSTable(CdcDictype.id, Sys.backendPath + "/cdc/cdcdictype/list", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(10);
    table.setShowColumns(false);
    table.setShowToggle(false);
    table.setOnClickRow(CdcDictype.ClickRow);
    table.setQueryParams({ NotQuery: true });
    CdcDictype.table = table.init();
});
